<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>日志管理</title>
    <link rel="stylesheet" href="plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="css/comments.css" media="all">
</head>
<body>
    <div class="maincontainer">
        <div class="layui-card">
            <div class="layui-card-header layuiadmin-card-header-auto">
                <form id="queryForm" class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">操作人</label>
                            <div class="layui-input-inline">
                                <input type="text" name="operateUserName" autocomplete="off" class="layui-input" placeholder="操作人" maxlength="20">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">操作时间</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="selectTime" placeholder=" - ">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn"  lay-submit lay-filter="searchBth">查询</button>
                            <button type="reset" class="layui-btn layui-btn-primary" >重置</button>
                        </div>
                    </div>
                </form>
            </div>
            <div class="layui-card-body">
                <table class="layui-hide" id="selectTable" lay-filter="selectTable"></table>
            </div>
        </div>
    </div>
</body>

<!-- table的toolbar -->
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container toolbarDemo">
		<button class="layui-btn layui-btn-primary layui-btn-sm" lay-event="export">导出</button>
	</div>
</script>
<script type="text/javascript" src="plugins/layui/layui.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script>
    
    layui.config({
        base: 'plugins/layui/modules/',
    }).use(['http', 'table', 'form', 'laydate'], function() {
        var http = layui.http,
            table = layui.table,
            form = layui.form,
            laydate = layui.laydate;
        var excelList, // 当前页表格数据
            currPage // 当前页码

        // 检测供应商是否审核通过
        http.checking(function() {
            // 操作时间
            laydate.render({
                elem: '#selectTime'
                ,theme: '#fbaf7e'
                ,range: "-"
            });

            // 后台用户列表
            var selectTable;
            selectTable = http.table({
                elem: '#selectTable',
                url: 'supplier/admin/log/listPage',
                method: 'get',
                id: 'selectTable',
                toolbar: '#toolbarDemo',
                done: function(res, curr, count){
                    excelList = res.data;
                    currPage = curr
                },
                cols: [[
                    {title:'序号',type:'numbers',fixed: 'left'}
                    ,{field:'operateUserName', title: '操作人', align : 'center'}
                    ,{field:'createTime', title: '操作时间', align : 'center'}
                    ,{field:'operateName', title: '操作动作', align : 'center'}
                ]]
            });

            // 查询
            form.on('submit(searchBth)', function (data) {
                let _data = data.field,
                    param = _data;
                var startTime = $('#selectTime').val()?$('#selectTime').val().split(' - ')[0]:'';
                var endTime = $('#selectTime').val()?$('#selectTime').val().split(' - ')[1]:'';
                param.startTime = startTime;
                param.endTime = endTime;
                selectTable.reload({
                    page:{curr:1},
                    where: param
                })
                return false;
            })

            // table的toolbar
            table.on('toolbar(selectTable)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
                var data = checkStatus.data; //获取选中行数据
                if(obj.event=='export'){ // 导出
                    var data = excelList; 
                    if (data.length == 0) {
                        layer.msg('当前页没有可导出的数据');
                        return;
                    }
                    var param = {
                        page: currPage,
                        limit: 10,
                        authentication: localStorage.getItem('xi-can-supplier-authentication'),
                        startTime: $('#selectTime').val()?$('#selectTime').val().split(' - ')[0]:'',
                        endTime: $('#selectTime').val()?$('#selectTime').val().split(' - ')[1]:'',
                        operateUserName: $('input[name=operateUserName]').val() // 操作人
                    }
                    if (param) {  
                        let paramsArray = [];  
                        //encodeURIComponent  
                        Object.keys(param).forEach(key => paramsArray.push(key + '=' + param[key]))  
                        window.open(TUrl+"supplier/admin/log/export?"+paramsArray.join('&'))
                    }
                    
                }
            })
        })
    })

</script>
</html>